#ifndef DIRECTINPUTTYPE_H
#define DIRECTINPUTTYPE_H

#include "inputtype.h"
#include <set>

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

bool operator<(const GUID& lhs, const GUID& rhs);
std::ostream& operator<<(std::ostream& o, const GUID& i);


class DirectInputType : public InputType
{
public:
  DirectInputType();
  virtual ~DirectInputType();

  virtual bool poll();
  virtual bool isOpen() const;

private:
  enum AXIS_TYPE
  {
    AXIS_LX,
    AXIS_LY,
    AXIS_LZ,
    AXIS_LRX,
    AXIS_LRY,
    AXIS_LRZ,
    AXIS_RGLSLIDER0,
    AXIS_RGLSLIDER1
  };

  typedef std::set<AXIS_TYPE> AxisSet;
  typedef std::set<unsigned int> ButtonSet;

  void close();
  void enumerate();
  void addAxis(const GUID& axisType);
  void addButton(const std::string& buttonType);

  static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE*  pdidoi,
                                           VOID* pContext);
  static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance,
                                             VOID* pContext);

  LPDIRECTINPUT8 mDirectInput;
  LPDIRECTINPUTDEVICE8 mGamepad;
  AxisSet mAxisTypes;
  ButtonSet mButtonTypes;
};

#endif
